Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sensors dynamically based on available device state #425

Merged
merged 37 commits into from
Aug 10, 2021

Conversation

iMicknl
Copy link
Owner

@iMicknl iMicknl commented Apr 18, 2021

Fixes #223

Screen Shot 2021-04-18 at 18 31 39

@iMicknl iMicknl marked this pull request as draft April 18, 2021 16:42
@iMicknl iMicknl marked this pull request as ready for review July 14, 2021 18:24
Copy link
Collaborator

@tetienne tetienne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan to clean the state_attributes method?

def device_state_attributes(self) -> Dict[str, Any]:

@tetienne
Copy link
Collaborator

I really like this PR :)

@tetienne tetienne force-pushed the feature/add_secondary_sensors branch from 3bdcccb to ea16b0a Compare July 21, 2021 10:14
@tetienne
Copy link
Collaborator

tetienne commented Jul 21, 2021

For my awning:

image

And my Energy meter (io:TotalElectricalEnergyConsumptionIOSystemSensor):

image

For this last, that’s not really readable.

@iMicknl
Copy link
Owner Author

iMicknl commented Jul 21, 2021

And my Energy meter (io:TotalElectricalEnergyConsumptionIOSystemSensor):

For this last, that’s not really readable.

Lol, I haven't seen a device like this yet. Maybe we should include the device name in the sensor name as well? Is your energy sensor one device, or is this part of our merge based on subsystemid (#1 + #2 etc.)

@tetienne
Copy link
Collaborator

tetienne commented Jul 21, 2021

Yes that’s the most complex devices I own :D That’s indeed a device merging several Somfy device.

    {
      "creationTime": 1496693986000,
      "lastUpdateTime": 1496693986000,
      "label": "Atlantic",
      "deviceURL": "io://xxxxxxx#1",
      "shortcut": false,
      "controllableName": "io:TotalElectricalEnergyConsumptionIOSystemSensor",
      "definition": {
        "commands": [],
        "states": [
          {
            "type": "DiscreteState",
            "values": [
              "good",
              "low",
              "normal",
              "verylow"
            ],
            "qualifiedName": "core:DiscreteRSSILevelState"
          },
          {
            "type": "ContinuousState",
            "qualifiedName": "core:ElectricEnergyConsumptionState"
          },
          {
            "type": "ContinuousState",
            "qualifiedName": "core:RSSILevelState"
          },
          {
            "type": "DiscreteState",
            "values": [
              "dead",
              "lowBattery",
              "maintenanceRequired",
              "noDefect"
            ],
            "qualifiedName": "core:SensorDefectState"
          },
          {
            "type": "DiscreteState",
            "values": [
              "available",
              "unavailable"
            ],
            "qualifiedName": "core:StatusState"
          }
        ],
        "dataProperties": [],
        "widgetName": "CumulativeElectricPowerConsumptionSensor",
        "uiProfiles": [
          "ElectricEnergyConsumption"
        ],
        "uiClass": "ElectricitySensor",
        "qualifiedName": "io:TotalElectricalEnergyConsumptionIOSystemSensor",
        "type": "SENSOR"
      },
      "states": [
        {
          "name": "core:StatusState",
          "type": 3,
          "value": "available"
        },
        {
          "name": "core:DiscreteRSSILevelState",
          "type": 3,
          "value": "good"
        },
        {
          "name": "core:RSSILevelState",
          "type": 2,
          "value": 100
        },
        {
          "name": "core:ElectricEnergyConsumptionState",
          "type": 1,
          "value": 22675960
        }
      ],
      "attributes": [
        {
          "name": "core:Manufacturer",
          "type": 3,
          "value": "Atlantic Group"
        },
        {
          "name": "core:MeasurementCategory",
          "type": 3,
          "value": "electric/overall"
        },
        {
          "name": "core:PowerSourceType",
          "type": 3,
          "value": "mainSupply"
        },
        {
          "name": "core:MeasuredValueType",
          "type": 3,
          "value": "core:ElectricalEnergyInWh"
        }
      ],
      "available": true,
      "enabled": true,
      "placeOID": "xxxxxx",
      "widget": "CumulativeElectricPowerConsumptionSensor",
      "measurementCategory": "ELECTRIC_OVERALL",
      "type": 2,
      "oid": "xxxxx",
      "uiClass": "ElectricitySensor"
    },

You can add by the way core:ElectricEnergyConsumptionState to your list ;)

@iMicknl
Copy link
Owner Author

iMicknl commented Jul 21, 2021

Do you plan to clean the state_attributes method?

def device_state_attributes(self) -> Dict[str, Any]:

I was thinking about removing this fully eventually, especially since this is not allowed in core. However, in the mean-time it can help us spot attributes / states that we should add.

@tetienne
Copy link
Collaborator

Do you think you will have some time to finish this PR. It's a nice improvement I would like to have.

@iMicknl
Copy link
Owner Author

iMicknl commented Jul 31, 2021

Do you think you will have some time to finish this PR. It's a nice improvement I would like to have.

I will take some time in the coming weeks, however I could use some help as well :). Feel free to contribute / test as well.

@tetienne
Copy link
Collaborator

tetienne commented Aug 1, 2021

Oki I will have a look too 😊

@tetienne tetienne force-pushed the feature/add_secondary_sensors branch from 23a73b8 to f959364 Compare August 3, 2021 19:49
@iMicknl iMicknl changed the title Add (secondary) state sensors Add sensors dynamically based on available device state Aug 4, 2021
@tetienne tetienne force-pushed the feature/add_secondary_sensors branch from 1152680 to d16f11d Compare August 5, 2021 07:33
@iMicknl iMicknl requested a review from tetienne August 9, 2021 15:45
custom_components/tahoma/const.py Show resolved Hide resolved
custom_components/tahoma/sensor.py Outdated Show resolved Hide resolved
custom_components/tahoma/sensor.py Show resolved Hide resolved
custom_components/tahoma/sensor.py Show resolved Hide resolved
custom_components/tahoma/sensor.py Show resolved Hide resolved
custom_components/tahoma/sensor.py Show resolved Hide resolved
tetienne
tetienne previously approved these changes Aug 10, 2021
Copy link
Collaborator

@tetienne tetienne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally. Seems to be OK. I can even now add my energy sensors within the Energy panel.

@iMicknl iMicknl merged commit 9505d8c into master Aug 10, 2021
@iMicknl iMicknl deleted the feature/add_secondary_sensors branch August 10, 2021 09:03
iMicknl added a commit that referenced this pull request Aug 10, 2021
commit 9505d8c
Author: Mick Vleeshouwer <Mick.Vleeshouwer@microsoft.com>
Date:   Tue Aug 10 02:03:19 2021 -0700

    Add sensors dynamically based on available device state (#425)

    * Add temporary state sensor

    * Add extra sensors

    * Add more states

    * Add more sensors

    * Create supported_platforms variable

    * Use Overkiz label as device name

    * Suffix state sensor name with device index

    * Avoid to duplicate state key

    * Remove now usless rssi level attribute

    * Migrate LightSensor to TahomaStateSensor

    * Apply linters

    * Add PriorityLockOriginatorState sensor

    * Bump minimum version to 2021.8

    * Remove unneeded value key

    * Migrate to SensorEntityDescription

    * Small tweaks

    * Add battery level

    * Remove unused state keys

    * Test electricity sensor

    * Add extra sensors

    * Add sensor

    * Add all sensors from sensor.py

    * Add smoke text sensor

    * Make optional

    * Change all sensor to new structure

    * Improve sensor definitions

    * Ease state

    * Ease retrieve of the index

    * Rollback device_state_attributes

    * Revert battery changes

    * Remove const

    * Add LightSensor

    * Rollback icon logic in cover

    * Bugfixes

    * Add round for RSSI value

    Co-authored-by: Thibaut Etienne <thibaut@etienne.pw>

commit e7a4554
Author: Mick Vleeshouwer <Mick.Vleeshouwer@microsoft.com>
Date:   Tue Aug 10 01:56:39 2021 -0700

    Add binary sensors dynamically based on available device state (#505)

    * Refactor binary sensor

    * Make import relative

    * Style fix

    * Update custom_components/tahoma/__init__.py

    Co-authored-by: Thibaut <thibaut@etienne.pw>

    * Add extra binary sensors

    * Clean for final PR

    * Feedback applied

    Co-authored-by: Thibaut <thibaut@etienne.pw>

commit da5b26e
Author: Mick Vleeshouwer <Mick.Vleeshouwer@microsoft.com>
Date:   Tue Aug 10 01:34:16 2021 -0700

    Temporary bugfix for AwningValance (until this is fixed serverside) (#511)

    * Temporary bugfix for #486

    * Add note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking Change feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Architecture] Allow multiple entities per device
2 participants